<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Admin_role_model extends MY_Model
{
	public $soft_delete = FALSE;

	public $_table = TABLE_ADMIN_ROLE;

	public $primary_key = 'id';

	public $return_type = 'array';

	public $select_field = 'id,depth,path,title,pid,visiable,c,a,url,static';
    
    function get_top_menu()
    {
       
    }
    //头部菜单
    function get_one($table,$where,$like)
    {
        $a_table=empty($table)?$this->_table:$table;
        $sql="select * from ".$this->db->dbprefix.$a_table." where ".$where.$like;
        $res=$this->db->query($sql)->row_array();
        return $res;
    }
    
    function post()
    {
      $sql="select * from qp_admin_role order by path asc";
      $res=$this->db->query($sql)->result_array();
      return $res;
    }
    //更新所有子路径
    function get_update($pid,$data)
    {
        $this->db->where('id', $pid);
        $this->db->update(TABLE_ADMIN_ROLE, $data); 
    }
    
    //获取path下的列表
    function get_path($path)
    {
        $query=$this->db->like('path', $path,'after')
                        ->get(TABLE_ADMIN_ROLE) ;
        $data=$query->result_array();
        $query->free_result();
        return $data;
    }
    //删除菜单级当前菜单下的所有内容
    function del_meun($path)
    {
       $this->db->like('path',$path, 'after')
                ->delete(TABLE_ADMIN_ROLE) ;
       return ($this->db->affected_rows()>0)?TRUE:FALSE;
    }
    
    function short_menu($val)
    {
        $query=$this->db->get_where(TABLE_ADMIN_ROLE,$val);
        $data=$query->result_array();
        $query->free_result();
        return $data;
    }
}